package main

import (
	_ "xinyuan/copy/routers"
	"github.com/astaxie/beego"
	"fmt"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
	"xinyuan/copy/models"
)

func init() {
	beego.SetLogger("file", `{"filename":"logs/test.log"}`)
	beego.SetLogFuncCall(true)
	beego.BeeLogger.SetLogFuncCallDepth(3)

	if beego.AppConfig.String("runmode") == "dev" {
		beego.SetLevel(beego.LevelDebug)
	} else {
		beego.SetLevel(beego.LevelInformational)
	}

	dataSource := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8",
		beego.AppConfig.String("mysqluser"),
		beego.AppConfig.String("mysqlpass"),
		beego.AppConfig.String("mysqlurls"),
		beego.AppConfig.String("mysqldb"))
	beego.Info("datasource:", dataSource)

	orm.RegisterDataBase("default", "mysql", dataSource, 30)
	// register model
	orm.RegisterModelWithPrefix("copy_", new(models.Item))
	// create table
	orm.RunSyncdb("default", false, true)
	orm.Debug = true
}

func main() {
	beego.Run()
}

